package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;

import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

@Slf4j
public class Practice5 {

    public static void main(String[] args) {

        Flux<Integer> flux1 = Flux.range(1, 10);
        Flux<Integer> flux2 = Flux.range(1, 6);

        Flux.zip(flux1, flux2, new BiFunction<Integer, Integer, Integer>() {
                    @Override
                    public Integer apply(Integer x, Integer y) {
                        log.info("sum {} + {}", x, y);
                        return x + y;
                    }
                })
                .mapNotNull(new Function<Integer, Integer>() {
                    @Override
                    public Integer apply(Integer i) {
                        log.info(String.valueOf(i));
                        return i;
                    }
                })
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer i) {
                        log.info(String.valueOf(i));
                    }
                });

    }
}
